<%@ page language="java"  contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"  %>
<%@include file="inc/comm.jsp" %>
<%@include file="inc/inc_head.jsp" %>
<html>
<head>
    <meta charset="utf-8"/>
    <title>首页</title>
    <link href="${ctx}/resources/style/share.css" rel="stylesheet" type="text/css" />
    <link href="${ctx}/resources/style/index.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="header">
    <div class="logo">
        <div class="logo-left">质量管理体系文件</div>
        <%--<div class="logo-right"></div>--%>
        <%--<div class="clear"></div>--%>
        <div class="logo-right">
            <ul class="nav ace-nav nav1">
                <li>
                    <a data-toggle="dropdown" href="${ctx}/" class="dropdown-toggle">
                        <img class="nav-user-photo" src="${ctx}/resources/avatars/user.jpg" alt="Jason's Photo"/>
								<span class="user-info">
									<small>欢迎光临</small>
                                    <strong id="username">${username}</strong>
								</span>
                        <i class="arrow fa fa-caret-down"></i>
                    </a>
                    <ul class="user-menu pull-right dropdown-menu dropdown-yellow dropdown-caret dropdown-close">
                        <li>
                           <a href="${pageContext.request.contextPath}/logout">
                                <i class="fa fa-power-off"></i>
                                退出
                           </a>
                        </li>
                        <%-- <li class="divider"></li>--%>
                    </ul>
                </li>

            </ul>
            <!-- /.ace-nav -->
        </div>
    </div>


    <div class="nav">
        <a href="#" name="1" onclick="jump(this)" class="index" id="first">体系首页</a>
        <a href="#" name="2" onclick="jump(this)" class="system" id="system">公司制度</a>
        <a href="#" name="3" onclick="jump(this)" class="role" id="role">业务角色</a>
        <a href="#" name="4" onclick="jump(this)" class="flow" id="flow">业务流程</a>
        <a href="${ctx}/info" name="5" onclick="addIframe(this); return false;" class="searchquick" id="searchquick">快速搜索</a>
        <a href="#" name="6" onclick="jump(this)" class="link" id="link">相关链接</a>
        <a href="#" name="7" onclick="jump(this)" class="scrum" id="scrum">敏捷（Scrum）开发</a>
        <a href="#" name="8" onclick="jump(this)" class="env" id="env">环境体系</a>
        <a href="#" name="9" onclick="jump(this)" class="info" id="info">信息安全</a>
    </div>
</div>
<div class="content">
    <div class="left" id="left" style=" background:#f9f9f9;">
        &nbsp;&nbsp;<a href="javasrcipt:;" name="index" id="addMenu" onclick="return add_menu(this);">添加菜单</a>
        <%--二级菜单添加--%>
        <div class="add_menu" style="display: none;">
            <form name="form" id="addSecond">
                <input type="text" name="name" id="m_c" value="">
                <input type="hidden" id="hiindex" name="parent" value="${pid}">
                <a href="javasrcipt:;" id="menuCon" name=""  onclick="return add_menu_x(this);">确定</a>
                <a href="javasrcipt:;" name="" onclick="return cancel_menu_x();">取消</a>
            </form>
        </div>

        <%--二级菜单--%>
        <ul id="index">
            <c:forEach items="${list}" var="item">
                <li>
                    <a href="<c:if test="${empty item.url}">${ctx}/upload?parentId=${pid}&secondId=${item.id}&name=${item.name}</c:if><c:if test="${not empty item.url}">${ctx}${item.url}</c:if>"
                       id="${pid}${item.id}" name="${item.id}" title="${item.name}"
                       onclick="secondIframe(this);return false;">${item.name}</a>
                    <%--三级菜单--%>
                    <ul class="tindex" id="tindex${item.id}">
                        <c:forEach items="${item.tlist}" var="it">
                            <li>
                                <a href="<c:if test="${empty it.url}">${ctx}/upload?parentId=${pid}&secondId=${item.id}&thirdId=${it.id}&name=${it.name}</c:if><c:if test="${not empty it.url}">${ctx}${it.url}</c:if>"
                                   name="${it.id}" id="${pid}${item.id}${it.id}" class="${item.id}" title="${it.name}"
                                   onclick="thirdIframe(this);return false;">${it.name}</a>
                            </li>
                        </c:forEach>
                        <a href="javasrcipt:;" class="identity" name="tindex" id="tindex${pid}${item.id}" onclick="return add_tmenu(this,'${item.id}','${pid}');">添加</a>
                            <%--三级菜单添加--%>
                        <div class="add_tmenu${pid}${item.id}" style="display: none;">
                            <form name="form" id="addThird">
                                <input type="text" name="name" id="tm_c${pid}${item.id}" value="">
                                    <%--<input type="hidden" id="hitindex" name="parent" value="${pid}">--%>
                                <a href="javasrcipt:;" id="tmenuCon${pid}${item.id}" name=""  onclick="return add_tmenu_x(this,'${item.id}','${pid}');">确定</a>
                                <a href="javasrcipt:;"  onclick="return cancel_tmenu_x('${item.id}','${pid}');">取消</a>
                            </form>
                        </div>
                    </ul>
                </li>
            </c:forEach>
        </ul>
        <%--<ul id="system" style=display:none>

                <c:forEach items="${list2}" var="item" >
                    <li><a href="${item.url}">${item.name}</a></li>
                </c:forEach>

        </ul>


        <ul id="role" style=display:none>

                <c:forEach items="${list3}" var="item" >
                    <li><a href="${item.url}">${item.name}</a></li>
                </c:forEach>

        </ul>

        <ul id="flow" style=display:none>

                <c:forEach items="${list4}" var="item" >
                    <li><a href="${item.url}">${item.name}</a></li>
                </c:forEach>

        </ul>

        <ul id="link" style=display:none>

                <c:forEach items="${list6}" var="item" >
                    <li><a href="${item.url}">${item.name}</a></li>
                </c:forEach>

        </ul>

        <ul id="scrum" style=display:none>

                <c:forEach items="${list7}" var="item" >
                    <li><a href="${item.url}">${item.name}</a></li>
                </c:forEach>

        </ul>

        <ul id="env" style=display:none>

                <c:forEach items="${list8}" var="item" >
                    <li><a href="${item.url}">${item.name}</a></li>
                </c:forEach>

        </ul>

        <ul id="info" style=display:none>

            <c:forEach items="${list9}" var="item">
                <li><a href="${item.url}">${item.name}</a></li>
            </c:forEach>
        </ul>--%>
    </div>
    <div class="right" id="right" style="border-left:1px solid #e5e5e5 !important;">
        <iframe src="${ctx}/home" name="content" id="content" style="border: none; overflow-y:visible; overflow-x:hidden;"
                width="100%" >
        </iframe>

    </div>
</div>

</body>
<script type="text/javascript">

    /*二级菜单操作*/
    function cancel_menu_x() {
        $('.add_menu').css('display', 'none');
        return false;
    }
    function add_menu_x(obj) {
        var menu_c = $('#m_c').val();
        var pid=${pid};

        $('.add_menu').css('display', 'none');

        //二级菜单的父节点
        var parentId = parseInt($('#hiindex').val());
        var menuId;
        $.ajax({
            type: "post",
            url: "${ctx}/add/second",
            data: "parentId=" + parentId + "&name=" + menu_c,
            success: function (data) {
                if(data==-1){
                    alert("该菜单已存在！请重新输入！");
                }else{
                    var li_new = "";
                    var id = $(obj).attr('name');
                    li_new = '<li><a href=' + '###' +' onclick='+'secondIframe(this);return&nbsp;false;'+' id='+pid+data+ ' title='+menu_c+ ' name='+data+'>' + menu_c + '</a></li>';
                    $('#' + id).append(li_new);
                    $('#content').attr('src', '');
                    $('#content').attr('src', '${ctx}/upload?parentId=' + parentId + '&secondId=' + data+'&name='+menu_c);
                }
            }
        });
        return false;
    }
    function add_menu(obj) {
        $('#m_c').val('');
        $('.add_menu').css('display', 'block');
        $('#menuCon').attr('name', $(obj).attr('name'));
        return false;
    }
    /*二级菜单操作*/


    /*三级菜单操作*/
    function cancel_tmenu_x(secondId,pid) {
        $('#tm_c'+pid+secondId).val('');
        $('.add_tmenu'+pid+secondId).css('display', 'none');
        $('#tindex'+pid+secondId).css('display', 'block');
        return false;
    }
    function add_tmenu_x(obj,secondId,pid) {
        $('.add_tmenu'+pid+secondId).css('display', 'none');
        $('#tindex'+pid+secondId).css('display', 'block');
        var menu_c = $('#tm_c'+pid+secondId).val();
        //三级菜单的父节点
        var pid=$(obj).attr('name');
        var ppid=$(obj).attr('class');
        //一级菜单的id
        var oneid=${pid};
        $('.add_tmenu').css('display', 'none');
        var menuId;
        $.ajax({
            type: "post",
            url: "${ctx}/add/third",
            data: "parentId=" + pid + "&name=" + menu_c,
            success: function (data) {
                if(data==-1){
                    alert("该菜单已存在！请重新输入！");
                }else{
                    var li_new = "";
                    var id = $(obj).attr('name');
                    li_new = '<li><a href=' + '###' +' onclick='+'thirdIframe(this);return&nbsp;false;'+' id='+oneid+pid+data+ ' name='+data+' class='+pid+' title='+menu_c+ '>' + menu_c + '</a></li>';
                    $('#tindex'+ppid).parent().prepend(li_new);
                    $('#content').attr('src', '');
                    $('#content').attr('src', '${ctx}/upload?parentId=' + oneid + '&secondId=' + pid+'&name='+menu_c+'&thirdId='+data);
                }
            }
        });
        return false;
    }
    function add_tmenu(obj,secondId,pid) {
        $('#tindex'+pid+secondId).css('display', 'none');
        $('#tm_c'+pid+secondId).val('');
        $('.add_tmenu'+pid+secondId).css('display', 'block');
        $('#tmenuCon'+pid+secondId).attr('name', secondId);
        $('#tmenuCon'+pid+secondId).attr('class',pid+ secondId);
        return false;
    }
    /*三级菜单操作*/

    /*一级菜单跳转*/
    function jump(obj){
        $('#addMenu').attr('name', $(obj).attr('class'));
        $('#add_tmenu').attr('name', $(obj).attr('class'));
        var name = $(obj).attr("name");
        var identity='${type}';
        $(obj).attr("href","${ctx}/index?pid="+name+"&type="+identity);
    }
    /*一级菜单跳转*/

    function thirdIframe(obj){
        var url=$(obj).attr('href');
        var name=$(obj).attr('title');
        var secondId=$(obj).attr('class');
        var thirdId=$(obj).attr('name');
        if(url=='' || url=='###'){
            $('#content').attr('src', '');
            $('#content').attr('src', '${ctx}/upload?parentId=${pid}&name='+name+'&secondId='+secondId+'&thirdId='+thirdId);
        }else{
            $('#content').attr('src', '');
            var _href = $(obj).attr('href');
            $('#content').attr('src', _href);
        }

    }



    function secondIframe(obj) {
        var dis=$(obj).parent().find('.tindex').css('display');
        if(dis=='none'){
            $(obj).parent().find('.tindex').css('display','block');
        }else{
            $(obj).parent().find('.tindex').css('display','none');
        }
        var url=$(obj).attr('href');
        var name=$(obj).attr('title');
        var id=$(obj).attr('name');

        if(url=='' || url=='###'){
            $('#content').attr('src', '');
            $('#content').attr('src', '${ctx}/upload?parentId=${pid}&name='+name+'&secondId='+id);
        }else{
            $('#content').attr('src', '');
//            var _href = $(obj).attr('href');
            $('#content').attr('src', url);
        }

        return false;
    }


    /* 获取iframe可视区域高度 */
    function refreshContentHeight() {
        var frame = document.getElementById('content');
        var contentHeight = $(window).height() -155;
        frame.setAttribute('height', contentHeight);
        var left=document.getElementById('left');
        left.setAttribute('height', contentHeight);
    }

    $(function () {
        var identity='${type}';
        if(identity==null || identity==''){
            $('#addMenu').css('display','none');
            $('.identity').each(function(){
                $('.identity').css('display','none');
            });
        }
        refreshContentHeight();
        $('.tindex').each(function(){
            $('.tindex').css('display','none');
        });

        var pid=${pid};
        var type = new Array('first', 'system', 'role', 'flow', 'searchquick','link', 'scrum', 'env', 'info');
        if(pid!='' && pid!=null){
            var ppid=parseInt(pid);
            $('#'+type[pid-1]).addClass('active');
        }else{
            $('#first').addClass('active');
        }

        $(window).resize(function () {
            refreshContentHeight();
            $("#sidebar").css("height", $(window).height() - 70 + "px");
            /* $(".slimScrollDiv").css("height", $(window).height() - 20 + "px");*/
        });

        $("#content").load(function () {
            refreshContentHeight();
        });
    });


    function addIframe(obj){
        $(obj).addClass('active');
        var type = new Array('first', 'system', 'role', 'flow', 'link', 'scrum', 'env', 'info');
        for(var i=0;i<type.length;i++){
            $('#'+type[i]).removeClass('active');
        }
        $('#content').attr('src', '');
        var _href = $(obj).attr('href');
        $('#content').attr('src', _href);
    }

</script>

</html>
